﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Axis.BusinessObject.Product;
using Axis.Dao.Product;
using Axis.Dao.Config;
using Axis.BusinessObject;

namespace Sotipha.Web.Views.Towntalk
{
    public partial class ProductDetail : CPage
    {
        public string LinkBanner = "#";
        protected void Page_Load(object sender, EventArgs e)
        {

            CConfigDao core = new CConfigDao();
            string inputValueConfig = string.Format("<InputValue ID=\"{0}\"/>", 3);
            IList<CConfigSite> listConfig = core.GetConfigSite(inputValueConfig);
            if (listConfig != null)
                if (listConfig.Count > 0)
                {
                    this.LinkBanner = listConfig[0].Link;
                    if (Session["lang"].ToString() == "vi")
                        ltrBanner.Text = string.Format("<img src=\"{0}\"  width=\"739\" style=\"margin-bottom: 7px\"/>", listConfig[0].Banner_VI);
                    else
                        ltrBanner.Text = string.Format("<img src=\"{0}\"  width=\"739\" style=\"margin-bottom: 7px\" />", listConfig[0].Banner_EN);
                }
            
            string ProductID = "-1";
            CProductDao coreProductGroup = new CProductDao();

           
            string listImage = "";
            if (Request.QueryString["ID"] != null)
                ProductID = Request.QueryString["ID"].ToString();          
            string inputValue = string.Format("<InputValue ProductID=\"{0}\" Context =\"FrontEnd\"/>", ProductID);
            #region Image
            IList<CProductImage> list = coreProductGroup.GetProductImage(inputValue);
            foreach (CProductImage Item in list) {
                listImage += string.Format("<li><a href=\"\"><img src=\"{0}\" src2=\"{1}\" /></a></li>", Item.Thumbnail, Item.LargeImage);
            }
            ltrImage.Text = listImage;
            #endregion

            #region Product

            inputValue = string.Format("<InputValue ID=\"{0}\" Context =\"Detail\"/>", ProductID);
            IList<CProduct> listProduct = coreProductGroup.GetProduct(inputValue);
            if(listProduct!=null)
                if (listProduct.Count > 0) {
                    CProduct Item = listProduct[0];
                    ltrPrice.Text = String.Format("{0:0,0}", Item.Price);
                    ltrPriceOld.Text = String.Format("{0:0,0}", Item.PriceOld);
                    if (Session["lang"].ToString() == "vi")
                    {
                        ltrEmailtoFriend.Text = "Gủi cho bạn bè";
                        ltrWriteReview.Text = "Tham khảo";
                        ltrAvailability.Text = "Trạng thái";
                        ltrOverview.Text = "Tổng quan";
                        ltrCall.Text = "Liên hệ ";
                        ltrQuality.Text = "Số lượng";
                        ltrSpecialPrice.Text = "Giá khuyến mại";
                        ltrRegularPrice.Text = "Giá";
                        if (Item.QuantityAvailable > 0)
                            ltrAvailabilityStatus.Text = "Đang có";
                        else
                            ltrAvailabilityStatus.Text = "Cháy hàng";

                        ltrNameProduct.Text = Item.Name_VN;
                        ltrDescription.Text = Item.Description_VN;
                      
                    }
                    else {
                        ltrNameProduct.Text = Item.Name_EN;
                        if (Item.QuantityAvailable > 0)
                            ltrAvailabilityStatus.Text = "In stock";
                        else
                            ltrAvailabilityStatus.Text = "Not Available";
                        ltrDescription.Text = Item.Description_EN;
                    }


                }
            #endregion

            string lang = "en";
            if (Session["lang"].ToString() == "vi")
                lang = "vi";
            string script = string.Format("var ProductID='{0}';\n var lang='{1}';\n", ProductID, lang);
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "Project_JS", script, true);

        }
    }
}